package com.hcj.admin.controller;

import com.hcj.admin.entity.TPermission;
import com.hcj.admin.entity.TUser;
import com.hcj.admin.service.ITPermissionService;
import com.hcj.admin.service.ITUserService;
import com.hcj.util.resultUtil.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.List;

/**
 * @Author: HuangChangjin 2017-10-24 10:02
 * @Description:
 */
@Controller
@RequestMapping("/index")
public class WelcomeController {
    private  static  final Logger logger = LoggerFactory.getLogger(WelcomeController.class);
    // inject via application.properties
//    @Value("${welcome.message:test}")
    @Value("${welcome.message}")
    private String message = "Hello World";
    @Autowired
    private ITUserService userService;
    @Autowired
    private ITPermissionService permissionService;

//    @RequestMapping(value = "/{id}/welcome", method = RequestMethod.GET)
    @GetMapping(value = "/{id}/welcome")
    public String welcome(Map<String, Object> model, @PathVariable String id) {
        logger.info("进入welcome");
        model.put("message", this.message);
        model.put("hello","问候世界");
        model.put("url","/index/"+ id +"/welcome");
        return "welcome";
    }

    @GetMapping("/test")
    @ResponseBody
    public Object test(){
        TUser user = userService.getByUserName("admin");
        logger.error("user={}",user);
        List<TPermission> list = permissionService.getByUserId(user == null ? "":user.getId());
        logger.error("list={}",list);
        return JsonResult.jsonSuccess(user);
    }
    @RequestMapping("/table")
    public String table() {
        logger.info("进入table");
        return "admin/tables";
    }

}
